﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Barbar.UrlGuard.Controls;
using Barbar.UrlGuard.Dal.Persist;
using Barbar.UrlGuard.Dal;
using Barbar.UrlGuard.BL;

namespace Barbar.UrlGuard {
  public partial class FormConfiguration : LocalizableForm, ILocalizable {
    public FormConfiguration() {
      InitializeComponent();
    }

    protected override void OnLoad(EventArgs e) {
      base.OnLoad(e);
      IDataContextHolder holder = ServiceLocator.Instance.Resolve<IDataContextHolder>();
      DataContext context = holder.Context;
      IInjectorUtility utility = ServiceLocator.Instance.Resolve<IInjectorUtility>();
      utility.LoadData<DataContext>(context, this);
    }

    #region ILocalizable Members

    public void Localize(ILocalizator localizator) {
      if (localizator == null)
        throw new ArgumentNullException("localizator");
      Text = localizator.Translate("FormConfiguration_Title");
      tabAlerts.Text = localizator.Translate("FormConfiguration_Alerts");
      tabCommon.Text = localizator.Translate("FormConfiguration_Common");
    }

    #endregion

    private void btnCancel_Click(object sender, EventArgs e) {
      Close();
    }

    private void btnApply_Click(object sender, EventArgs e) {
      IDataContextHolder holder = ServiceLocator.Instance.Resolve<IDataContextHolder>();
      IInjectorUtility utility = ServiceLocator.Instance.Resolve<IInjectorUtility>();
      utility.SaveData<DataContext>(holder.Context, this);
      holder.Persist();
      Close();
    }
  }
}
